package com.wanjia.estate.constant;

import cn.hutool.core.collection.CollUtil;
import lombok.AllArgsConstructor;

import java.util.List;
import java.util.Objects;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@AllArgsConstructor
public enum Yhzgx {

    GX01("01", "本人"),
    GX02("02", "户主"),
    GX10("10", "配偶"),
    GX11("11", "夫"),
    GX12("12", "妻"),
    GX20("20", "子"),
    GX21("21", "独生子"),
    GX22("22", "长子"),
    GX23("23", "次子"),
    GX24("24", "三子"),
    GX25("25", "四子"),
    GX26("26", "五子"),
    GX27("27", "养子或继子"),
    GX28("28", "女婿"),
    GX29("29", "其他儿子"),
    GX30("30", "女"),
    GX31("31", "独生女"),
    GX32("32", "长女"),
    GX33("33", "次女"),
    GX34("34", "三女"),
    GX35("35", "四女"),
    GX36("36", "五女"),
    GX37("37", "养女或继女"),
    GX38("38", "儿媳"),
    GX39("39", "其他女儿"),
    GX40("40", "孙子、孙女或外孙子、外孙女"),
    GX41("41", "孙子"),
    GX42("42", "孙女"),
    GX43("43", "外孙子"),
    GX44("44", "外孙女"),
    GX45("45", "孙媳妇或外孙媳妇"),
    GX46("46", "孙女婿外孙女婿"),
    GX47("47", "曾孙子或曾外孙子"),
    GX48("48", "曾孙女或曾外孙女"),
    GX49("49", "其他孙子、孙女或外孙子、外孙女"),
    GX50("50", "父母"),
    GX51("51", "父亲"),
    GX52("52", "母亲"),
    GX53("53", "公公"),
    GX54("54", "婆婆"),
    GX55("55", "岳父"),
    GX56("56", "岳母"),
    GX57("57", "继父或养父"),
    GX58("58", "继母或养母"),
    GX59("59", "其他父母关系"),
    GX60("60", "祖父母或外祖父母"),
    GX61("61", "祖父"),
    GX62("62", "祖母"),
    GX63("63", "外祖父"),
    GX64("64", "外祖母"),
    GX65("65", "配偶的祖父母或外祖父母"),
    GX66("66", "曾祖父"),
    GX67("67", "曾祖母"),
    GX68("68", "配偶的曾祖父母或外曾祖父母"),
    GX69("69", "其他祖父母或外祖父母关系"),
    GX70("70", "兄弟姐妹"),
    GX71("71", "兄"),
    GX72("72", "嫂"),
    GX73("73", "弟"),
    GX74("74", "弟媳"),
    GX75("75", "姐姐"),
    GX76("76", "姐夫"),
    GX77("77", "妹妹"),
    GX78("78", "妹夫"),
    GX79("79", "其他兄弟姐妹"),
    GX80("80", "其他"),
    GX81("81", "伯父"),
    GX82("82", "伯母"),
    GX83("83", "叔父"),
    GX84("84", "婶母"),
    GX85("85", "舅父"),
    GX86("86", "舅母"),
    GX87("87", "姨父"),
    GX88("88", "姨母"),
    GX89("89", "姑父"),
    GX90("90", "姑母"),
    GX91("91", "堂兄弟、堂姐妹"),
    GX92("92", "表兄弟、表姐妹"),
    GX93("93", "侄子"),
    GX94("94", "侄女"),
    GX95("95", "外甥"),
    GX96("96", "外甥女"),
    GX97("97", "其他亲属"),
    GX99("99", "非亲属");

    private final String code;
    private final String desc;

    public String code() {
        return code;
    }

    public String desc() {
        return desc;
    }

    public static Yhzgx get(String code) {
        return Stream.of(values())
                .filter(s -> Objects.equals(code, s.code))
                .findFirst()
                .orElse(null);
    }

    public static Yhzgx getOrElse(String code, Yhzgx orElse) {
        return Stream.of(values())
                .filter(s -> Objects.equals(code, s.code))
                .findFirst()
                .orElse(orElse);
    }

    public static Yhzgx getOrElseGet(String code, Supplier<Yhzgx> supplier) {
        return Stream.of(values())
                .filter(s -> Objects.equals(code, s.code))
                .findFirst()
                .orElseGet(supplier);
    }

    public static <X extends Throwable> Yhzgx getOrElseThrow(String code, Supplier<? extends X> supplier) throws X {
        return Stream.of(values())
                .filter(s -> Objects.equals(code, s.code))
                .findFirst()
                .orElseThrow(supplier);
    }

    /**
     * 父母
     */
    public static final List<Yhzgx> PARENT = CollUtil.newArrayList(GX50, GX51, GX52);

    public static final List<String> PARENT_CODE = PARENT.stream()
            .map(Yhzgx::code)
            .collect(Collectors.toList());

    /**
     * 夫妻
     */
    public static final List<Yhzgx> SPOUSE = CollUtil.newArrayList(GX10, GX11, GX12);

    public static final List<String> SPOUSE_CODE = SPOUSE.stream()
            .map(Yhzgx::code)
            .collect(Collectors.toList());

    /**
     * 兄弟姐妹
     */
    public static final List<Yhzgx> BROTHER_AND_SISTER = CollUtil.newArrayList(GX70, GX71, GX73, GX75, GX77, GX79);

    public static final List<String> BROTHER_AND_SISTER_CODE = BROTHER_AND_SISTER.stream()
            .map(Yhzgx::code)
            .collect(Collectors.toList());

    /**
     * 子女
     */
    public static final List<Yhzgx> CHILDREN = CollUtil.newArrayList(
            GX20, GX21, GX22, GX23, GX24, GX25, GX26, GX27, GX29, GX30, GX31, GX32, GX33, GX34, GX35, GX36, GX37, GX39);

    public static final List<String> CHILDREN_CODE = CHILDREN.stream()
            .map(Yhzgx::code)
            .collect(Collectors.toList());
}
